// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import 'element-ui/lib/theme-chalk/index.css'
import ElementUI from 'element-ui'
import './assets/css/reset.css'
import { Message } from 'element-ui'
Vue.use(ElementUI);

Vue.prototype.$message = Message
Vue.config.productionTip = false

/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  components: { App },
  template: '<App/>'
})

router.beforeEach((to, from, next)=>{
  // console.log(to);
  // console.log(from);
  if(to.meta.requireAuth){
    // 判断该路由是否需要登录权限
    if(localStorage.getItem("user") !== null){
      // 如果在localStorage中存在用户则允许登录
      // console.log(localStorage.getItem("user"));
      next();
    }
    else{
      alert("请先登录！！！");
      if(to.path === "/login"){
        next();
      }
      else{
        next({path:'/login'});
      }
    }
  }else{
    next();
  }
});
